package smashedapples.google.datastore.commands
{
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	import smashedapples.google.datastore.events.DataStoreSaveEvent;
		
	[Event(name="success",type="smashedapples.google.datastore.events.DataStoreSaveEvent")]
	
	public class SaveCommand extends BaseCommand 
	{
		public function SaveCommand( modelName:String=null, result:Function = null, fault:Function = null )
		{
			super( modelName );
			
			if( result != null )
				this._result = result;
			
			if( fault != null )
				this._fault = fault;
		}
		
		private var _result:Function;
		private var _fault:Function;
	
		public function result( event:ResultEvent ):void
		{
			if( _result != null )
				_result( event );	
				
			dispatchEvent( new DataStoreSaveEvent( DataStoreSaveEvent.SUCCESS, this.modelName, event.result ));
		}
		
		public function fault( event:FaultEvent ):void
		{
			if( _fault != null )
				_fault( event );
		}
		
		

	}
}